<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/11/1
  Time: 15:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="layui/css/login.css">
    <title>注册页面</title>
</head>
<body>
<div class="login-main">
    <header class="layui-elip">用户注册</header>
    <form class="layui-form" action="regist" method="post" onsubmit="return check()">
        <div class="layui-input-inline">
            <label>
                <input type="text" id="user" name="name" required placeholder="用户名" class="layui-input">
            </label>
        </div>
        <div class="layui-input-inline">
            <label>
                <input type="password" id="pwd"name="password" required  placeholder="密码" class="layui-input">
            </label>
        </div>
        <div class="layui-input-inline">
            <label>
                <input type="password" id="repwd" name="password" required  placeholder="确认密码" class="layui-input">
            </label>
        </div>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="男" title="男" checked>
                <input type="radio" name="sex" value="女" title="女">
            </div>
            <div class="layui-input-inline">
                <select name="question" lay-verify="required">
                    <option value="">请选择一个密保问题</option>
                    <option value="出生年月">你的出生年月？</option>
                    <option value="小学地点">你的小学地点？</option>
                    <option value="手机号码">你的手机号码？</option>
                    <option value="你父亲的名字">你父亲的名字？</option>
                    <option value="你母亲的名字">你母亲的名字？</option>
                </select>
            </div>
        <div class="layui-input-inline">
            <label>
                <input type="text" id="answer" name="answer" required  placeholder="请输入密保答案" class="layui-input">
            </label>
        </div>
            <div class="layui-input-inline">
                <textarea id="desc" name="desc" required placeholder="请输入个人介绍" class="layui-textarea"></textarea>
            </div>
        <div class="layui-input-inline login-btn">
            <button class="layui-btn">注册</button>
        </div>
        <hr/>
    </form>
</div>
<script>
    function check(){
        var $user_name = document.getElementById("user").value;
        var $user_pwd = document.getElementById("pwd").value;
        var $user_repwd = document.getElementById("repwd").value;
        var $flag=false;
        const $=layui.$;
        if($user_pwd!=$user_repwd) {
            layer.msg("两次密码不一致");
            return $flag;
        }
        $.ajax({
                url: '/Test1_war/user/select/',
                type: 'POST',
                data: {username: $user_name},
                async: false,
                success: function (res) {
                    if (res.code === 200) {
                        alert('注册成功');
                        $flag=true;
                    } else {
                        layer.msg('用户名已存在');
                    }
                }
                , error(error) {
                    layer.close(index)
                    layer.msg('http请求错误')
                }
            });
        return $flag;
    }
</script>
<script src="layui/layui.all.js"></script>
</body>
</html>
